package com.mingyizhudao.app.view;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.baidu.mobstat.StatService;
import com.dixiang.framework.BaseActivity;
import com.mingyizhudao.app.R;

public abstract class MYBaseActivity extends BaseActivity{
	public Activity activity;
	private View actionBarView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		activity = this;
		
	}
	
	
	@Override
	protected void onResume() {
		super.onResume();
		initHeaderView();
		StatService.onResume(activity);
//		umeng
//		MobclickAgent.onResume(activity);//统计

	}
	
	
	@Override
	protected void onPause()
	{
		super.onPause();
//		umeng
//		MobclickAgent.onPause(activity);//统计
		StatService.onPause(activity);
	}
	public abstract void initHeaderView();
	
	
	public void initBackView(int resourseId,int stringId,OnClickListener onListener){
		View backView = findViewById(R.id.back_view);
		ImageView img_back = (ImageView)findViewById(R.id.img_back);
		TextView txt_back = (TextView)findViewById(R.id.lab_back);
		
		if(resourseId != 0){
			img_back.setBackgroundResource(resourseId);
		}
		if(stringId != 0){
			txt_back.setText(stringId);
		}
		backView.setOnClickListener(onListener);
	}
	

	public void initBackView(OnClickListener onListener){
		initBackView(0,0,onListener);
	}

	public void initBackView(boolean isShow){
		View backView = findViewById(R.id.back_view);
		if(!isShow) {
			backView.setVisibility(View.GONE);
		}else {
			backView.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					finish();
				}
			});
		}
	}

	
	public void initOptionView(int resourseId,int stringId,OnClickListener onListener){
		View optionView = findViewById(R.id.option_view);
		optionView.setVisibility(View.VISIBLE);
		ImageView img_option = (ImageView)findViewById(R.id.img_option);
		TextView txt_option = (TextView)findViewById(R.id.lab_option);
		
		if(resourseId != 0){
			img_option.setBackgroundResource(resourseId);
		}
		if(stringId != 0){
			txt_option.setText(stringId);
		}
		optionView.setOnClickListener(onListener);
	}
	
	public void setRightText(String rightText,int colorid){
		TextView txt_option = (TextView)findViewById(R.id.lab_option);
		txt_option.setVisibility(View.VISIBLE);
		txt_option.setText(rightText);
		if(colorid != 0){
			txt_option.setTextColor(getResources().getColor(colorid));
		}
	}
	
	public void initOptionView(OnClickListener onListener){
		initOptionView(0,0,onListener);
	}
	
	
	public void setTitleViewValue(int stringId){
		setTitleViewValue(stringId ,0,0);
	}
	
	public void setTitleViewValue(int stringId ,int size,int colorid){
		TextView title = (TextView)findViewById(R.id.lab_title);
		title.setVisibility(View.VISIBLE);
		if(size != 0){
			title.setTextSize(size);
		}

		if(stringId != 0){
			title.setText(stringId);	
		}
		
		if(colorid != 0){
			title.setTextColor(getResources().getColor(colorid));
		}
	}
	
	public void setTitleViewValue(String stringText){
		TextView title = (TextView)findViewById(R.id.lab_title);
		title.setVisibility(View.VISIBLE);
		title.setText(stringText);
	}
	
	public void setTitleViewValue(String stringText,int colorid ,int rightDrawable,OnClickListener onListener){
		
		TextView title = (TextView)findViewById(R.id.lab_title);
		title.setVisibility(View.VISIBLE);
		title.setText(stringText);
		
		Drawable drawable = getResources().getDrawable(rightDrawable);
		drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
		
		title.setCompoundDrawables(null, null, drawable, null);//画在右边
		title.setCompoundDrawablePadding(3);
		
		if(colorid != 0){
			title.setTextColor(getResources().getColor(colorid));
		}
		if (onListener!=null) {
			title.setOnClickListener(onListener);
		}
		
	}
	
	public void initCenterView(View view){
		
		RelativeLayout sel_view = (RelativeLayout) findViewById(R.id.sel_view);
		sel_view.setVisibility(View.VISIBLE);
		sel_view.addView(view);
		
		TextView title = (TextView)findViewById(R.id.lab_title);
		title.setVisibility(View.GONE);
	}
	
	public void clearTitle(){
		View backView = activity.findViewById(R.id.back_view);
		backView.setVisibility(View.GONE);
		
		View sel = activity.findViewById(R.id.sel_view);
		sel.setVisibility(View.GONE);
		
		View optionView = activity.findViewById(R.id.option_view);
		optionView.setVisibility(View.GONE);
	}
	
	
	public void initMenuView(){
		((RadioButton)findViewById(R.id.rb1)).setChecked(true);
	}

	
	@SuppressLint("NewApi")
	public void setTopViewBg(int resourseId){
		View topView = findViewById(R.id.actionbar);
		Drawable drawable = activity.getResources().getDrawable(resourseId);
		topView.setBackground(drawable);
	}
	
    
}
